<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Guava函数式编程深度解析</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            transition: all 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            overflow-x: auto;
            position: relative;
        }
        
        .code-block pre {
            margin: 0;
            padding: 1.5rem;
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
            font-size: 14px;
            line-height: 1.6;
        }
        
        .section-title {
            position: relative;
            padding-left: 1rem;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            padding: 1rem 1.5rem;
            border-radius: 8px;
            margin: 1.5rem 0;
        }
        
        .feature-card {
            background: white;
            border-radius: 12px;
            padding: 2rem;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
        }
        
        .feature-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 15px 40px rgba(0, 0, 0, 0.15);
        }
        
        .mermaid {
            text-align: center;
            margin: 2rem 0;
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            margin-top: -0.2rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        
        .quote-box {
            border-left: 4px solid #667eea;
            padding-left: 1.5rem;
            margin: 2rem 0;
            font-style: italic;
            color: #4a5568;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto text-center">
                <h1 class="text-5xl font-bold mb-6 tracking-tight">
                    <i class="fas fa-code-branch mr-4"></i>
                    Guava函数式编程深度解析
                </h1>
                <p class="text-xl opacity-90 leading-relaxed">
                    探索Java函数式编程的优雅实现，从设计原理到实战应用的全方位解读
                </p>
                <div class="mt-8 flex justify-center space-x-4">
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                        <i class="fas fa-clock mr-2"></i>深度技术文章
                    </span>
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                        <i class="fas fa-user mr-2"></i>高级开发者
                    </span>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12 max-w-5xl">
        <!-- Introduction -->
        <div class="content-card rounded-xl shadow-xl p-8 mb-8">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">在</span>Java 8之前，函数式编程在Java中一直是个痛点。记得我曾经为了在Java 6项目中实现一个简单的map操作，写了一堆匿名内部类，代码臃肿得令人发指。直到接触了Guava的函数式工具，才让我看到了曙光。Guava的函数式编程工具包虽然在Java 8后光芒减弱，但其设计思想和实现技巧依然值得我们学习。
            </p>
        </div>

        <!-- Section 1 -->
        <div class="content-card rounded-xl shadow-xl p-8 mb-8">
            <h2 class="text-3xl font-bold mb-6 section-title text-gray-800">
                1. 函数式接口设计与实现原理
            </h2>
            
            <p class="text-gray-700 mb-6 leading-relaxed">
                在Java 8之前，Guava通过一系列精心设计的函数式接口，将函数式编程的思想引入Java。这些接口构成了Guava函数式编程的基础。
            </p>

            <h3 class="text-2xl font-semibold mb-4 text-gray-800">
                <i class="fas fa-cube mr-2 text-purple-600"></i>
                1.1 核心函数式接口
            </h3>

            <p class="text-gray-700 mb-4">Guava定义了几个核心的函数式接口：</p>

            <div class="code-block mb-6">
                <pre><code>// 接收一个输入，产生一个输出
public interface Function&lt;F, T&gt; {
    @Nullable
    T apply(@Nullable F input);
    
    @Override
    boolean equals(@Nullable Object object);
}

// 接收一个输入，产生一个布尔值
public interface Predicate&lt;T&gt; {
    boolean apply(@Nullable T input);
    
    @Override
    boolean equals(@Nullable Object object);
}

// 不接收输入，但提供一个值
public interface Supplier&lt;T&gt; {
    T get();
}

// 接收一个输入，不返回结果
public interface Consumer&lt;T&gt; {
    void accept(T input);
}</code></pre>
            </div>

            <div class="highlight-box">
                <i class="fas fa-lightbulb mr-2"></i>
                这些接口设计得非常简洁，每个接口只负责一种转换模式，符合单一职责原则。通过组合这些基本接口，可以构建出复杂的函数式操作链。
            </div>

            <h3 class="text-2xl font-semibold mb-4 text-gray-800">
                <i class="fas fa-tools mr-2 text-purple-600"></i>
                1.2 Functions工具类分析
            </h3>

            <p class="text-gray-700 mb-4">
                <code class="bg-gray-100 px-2 py-1 rounded">Functions</code>类是Guava函数式编程的核心工具类，提供了创建和操作Function实例的静态方法：
            </p>

            <div class="code-block mb-6">
                <pre><code>// Functions.java (简化版)
public final class Functions {
    private Functions() {}
    
    // 返回常量值的Function
    public static &lt;E&gt; Function&lt;Object, E&gt; constant(@Nullable final E value) {
        return new ConstantFunction&lt;E&gt;(value);
    }
    
    private static class ConstantFunction&lt;E&gt; implements Function&lt;Object, E&gt;, Serializable {
        private final E value;
        
        public ConstantFunction(@Nullable E value) {
            this.value = value;
        }
        
        @Override
        public E apply(@Nullable Object from) {
            return value;
        }
        
        // 其他方法（equals, hashCode, toString等）
    }
    
    // 函数组合，f(g(x))
    public static &lt;A, B, C&gt; Function&lt;A, C&gt; compose(
            Function&lt;B, C&gt; f, Function&lt;A, ? extends B&gt; g) {
        return new FunctionComposition&lt;A, B, C&gt;(f, g);
    }
    
    private static class FunctionComposition&lt;A, B, C&gt; 
            implements Function&lt;A, C&gt;, Serializable {
        private final Function&lt;B, C&gt; f;
        private final Function&lt;A, ? extends B&gt; g;
        
        public FunctionComposition(Function&lt;B, C&gt; f, Function&lt;A, ? extends B&gt; g) {
            this.f = checkNotNull(f);
            this.g = checkNotNull(g);
        }
        
        @Override
        public C apply(@Nullable A a) {
            return f.apply(g.apply(a));
        }
        
        // 其他方法（equals, hashCode, toString等）
    }
    
    // 其他辅助方法...
}</code></pre>
            </div>

            <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-6">
                <div class="feature-card">
                    <h4 class="font-semibold text-lg mb-2 text-purple-700">
                        <i class="fas fa-lock mr-2"></i>高度封装
                    </h4>
                    <p class="text-gray-600">每种功能都封装为独立的静态内部类</p>
                </div>
                <div class="feature-card">
                    <h4 class="font-semibold text-lg mb-2 text-purple-700">
                        <i class="fas fa-shield-alt mr-2"></i>不可变性
                    </h4>
                    <p class="text-gray-600">所有实现类都是不可变的，确保线程安全</p>
                </div>
                <div class="feature-card">
                    <h4 class="font-semibold text-lg mb-2 text-purple-700">
                        <i class="fas fa-layer-group mr-2"></i>组合模式
                    </h4>
                    <p class="text-gray-600">通过compose方法支持函数组合，实现f(g(x))</p>
                </div>
                <div class="feature-card">
                    <h4 class="font-semibold text-lg mb-2 text-purple-700">
                        <i class="fas fa-hourglass-half mr-2"></i>懒惰计算
                    </h4>
                    <p class="text-gray-600">函数只有在apply被调用时才执行，支持惰性求值</p>
                </div>
            </div>
        </div>

        <!-- Mermaid Diagram -->
        <div class="content-card rounded-xl shadow-xl p-8 mb-8">
            <h3 class="text-2xl font-semibold mb-6 text-center text-gray-800">
                <i class="fas fa-project-diagram mr-2 text-purple-600"></i>
                Guava函数式编程核心概念关系图
            </h3>
            <div class="mermaid">
                graph TB
                    A[函数式接口] --> B[Function]
                    A --> C[Predicate]
                    A --> D[Supplier]
                    A --> E[Consumer]
                    
                    B --> F[Functions工具类]
                    C --> G[Predicates工具类]
                    
                    F --> H[compose组合]
                    F --> I[constant常量]
                    G --> J[and/or逻辑组合]
                    G --> K[not取反]
                    
                    L[集合操作] --> M[Iterables]
                    L --> N[Lists]
                    L --> O[FluentIterable]
                    
                    M --> P[transform转换]
                    M --> Q[filter过滤]
                    N --> P
                    O --> R[链式API]
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                    style L fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                    style O fill:#f093fb,stroke:#fff,stroke-width:2px,color:#fff
            </div>
        </div>

        <!-- Section 2 -->
        <div class="content-card rounded-xl shadow-xl p-8 mb-8">
            <h2 class="text-3xl font-bold mb-6 section-title text-gray-800">
                2. 集合转换与函数应用机制
            </h2>

            <h3 class="text-2xl font-semibold mb-4 text-gray-800">
                <i class="fas fa-exchange-alt mr-2 text-purple-600"></i>
                2.1 集合转换功能实现
            </h3>

            <p class="text-gray-700 mb-4">
                Guava提供了强大